<template>
  <div class="borad_main">
    <div class="borad_main_title">
      <div class="search-box">
        <el-menu :default-active="activeCode" class="search-menu-box" mode="horizontal" @select="onMenuClick">
          <el-menu-item v-for="(item, key) in menuInfo" :key="key" :index="key">
            {{ item.label }}
            <!-- （{{ item.num }}） -->
          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <div class="borad_box" v-if="weekShow">
      <WeekBoard :weekList="weekList" :userId="userId" :recordType="firstType" @commit="commitData" />
    </div>
  </div>
</template>

<script>
import WeekBoard from './WeekBoard'
import { getlistRecordNoteCalendarV2 } from '@apis/board.js'
export default {
  name: 'documentAry',
  components: {
    WeekBoard,
  },
  data() {
    return {
      menuInfo: {
        week: {
          label: '周纪实',
          num: 0,
          type: '01-01',
        },
        month: {
          label: '月小结',
          num: 0,
          type: '01-02',
        },
        quarter: {
          label: '季度总结',
          num: 0,
          type: '01-03',
        },
        year: {
          label: '年度总结',
          num: 0,
          type: '01-05',
        },
      },
      activeCode: 'week',
      weekList: [],
      userId: '',
      weekShow: true,
      // 评价跳转纪实路由参数
      evaluateRouter: {},
      firstType: '01-01',
    }
  },
  created() {
    this.activeCode = this.$store.state.boardTabs || 'week'
    this.firstType = this.menuInfo[this.activeCode].type
  },
  mounted() {
    console.log('this.menuInfo :>> ', this.menuInfo)
  },
  methods: {
    // 获取人员纪实
    getData(userId, noteId) {
      this.userId = userId
      this.weekShow = false
      if (!this.userId) return (this.weekList = [])
      getlistRecordNoteCalendarV2({
        optionUserId: localStorage.pskh_userId,
        recordType: this.firstType,
        userId: userId,
        tenantId: localStorage.pskh_tenantId,
      }).then(res => {
        const weekList = []
        const data = res.data
        for (let i = 0; i < data.length; i++) {
          const dataDetail = {
            dataDetail: [],
            suggestList: [],
            recordDoubleList: [],
            mainLeader: { isRepayAuth: '', mainLeaderSuggest: '' },
          }
          data[i].isOpen = false
          const newData = Object.assign(data[i], dataDetail)
          weekList.push(newData)
        }
        if (noteId) {
          for (let i = 0; i < weekList.length; i++) {
            if (weekList[i].saveStatus === '1' && weekList[i].id === noteId) {
              weekList[i].isOpen = true
              break
            }
          }
        } else {
          for (let i = 0; i < weekList.length; i++) {
            if (weekList[i].saveStatus === '1') {
              weekList[i].isOpen = true
              this.index = i
              break
            }
          }
        }
        this.weekList = weekList
        this.weekShow = true
      })
    },

    commitData() {
      this.getData(this.userId)
    },
    onMenuClick(code) {
      this.activeCode = code
      this.firstType = this.menuInfo[code].type
      this.$store.state.boardTabs = code
      this.getData(this.userId)
    },
  },
}
</script>

<style lang="scss" scoped>
.borad_main {
  height: 100%;
  .borad_main_title {
    height: 60px;
    .search-box {
      .el-menu {
        .is-active {
          font-weight: bold;
          font-size: 16px;
        }
      }
    }
  }
  .borad_box {
    height: calc(100% - 60px);
  }
}
</style>
